package org.studle.domain;

import java.util.HashSet;
import java.util.Set;

import org.studle.utilities.*;

public class Person extends Attendee {
	private String email; //KEY
	private String password;
	private Set<UserRoles> roles;
	private static Validator validator = new Validator();
	
	public static enum UserRoles {
		ADMINISTRATOR, USER, OWNER
	}
	
	public Person(String name, String email, String password) throws IllegalArgumentException {
			super(name);
			if (!validator.validate(validator.emailPattern, email)) throw new IllegalArgumentException("Email: " + email+" validation failed");
			if (!validator.validate(validator.passwordPattern, password)) throw new IllegalArgumentException("Improper password");
			this.email = email;
			this.password = password;
			this.roles = new HashSet<UserRoles>();
		}
		
	public void addRole(UserRoles role){
		this.roles.add(role);
	}
	
	public boolean hasRole(UserRoles role){
		return this.roles.contains(role);
	}
	
	public void setPassword(String password){
		if (!validator.validate(validator.passwordPattern, password)) throw new IllegalArgumentException("Improper password");
		this.password = password;
	}
	
	public String getEmail(){
		return this.email;
	}
		
}
